package heima.lm.oschina.vpfragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import heima.lm.oschina.R;
import heima.lm.oschina.adapter.RecentActivitiesAdapter;
import heima.lm.oschina.base.BaseFragment;
import heima.lm.oschina.bean.Event;
import heima.lm.oschina.bean.EventList;
import heima.lm.oschina.constant.Constants;
import heima.lm.oschina.utils.HttpUtils;
import heima.lm.oschina.utils.UIUtils;

/**
 * Created by Administrator on 2017/4/7.
 */

public class RecentActivitiesFragment extends BaseFragment {

    private List<Event> mList;

    @BindView(R.id.srl_latest_sweet)
    SwipeRefreshLayout mSwipeRefreshLayout;

    @BindView(R.id.rv_latest_tweet)
    RecyclerView mRecyclerView;

    @Override
    protected void loadSuccessPager() {
        View successView = View.inflate(UIUtils.getContext(), R.layout.fragment_latest_tweet, null);
        ButterKnife.bind(this, successView);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(new RecentActivitiesAdapter(mList));
        mCommonPager.changeView(successView);

    }

    @Override
    protected void loadData() {
        HttpUtils<EventList> httpUtils = new HttpUtils<>();
        Map<String, String> params = new HashMap<>();
        params.put("page", "0");
        httpUtils.getData(Constants.Http.MY_EVENT_LIST, params, EventList.class, new HttpUtils.OnHttpResponseListener<EventList>() {
            @Override
            public void onSuccess(EventList bean) {
                mList = bean.getList();
                mCommonPager.dealCommonSuccess(mList);
            }

            @Override
            public void onFailure(Exception e) {
                mCommonPager.dealCommonFailure();
            }
        });
    }

}
